package com.premedsidekick;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;

public class MCATschedule extends ListActivity {
	String[] weeks;
	Intent intent;
	Context context;
	public void onCreate (Bundle bundle) {
		super.onCreate (bundle);
		
		//weeks = getResources().getStringArray(R.array.mcat_schedule_overview);
		setListAdapter(new MCATscheduleAdapter());

		
		ListView lv = getListView();
		lv.setTextFilterEnabled(true);

		lv.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				context = getBaseContext();
				if (id == 0) {
					intent = new Intent (context, MCATweek1.class);
				}
				startActivity (intent);
		    }
		});
	}		
	public class MCATscheduleAdapter extends BaseAdapter {
		LayoutInflater inflater;
		String[] weeks;
		Viewholder viewholder;
		
		MCATscheduleAdapter() {
			super();
			inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			weeks = getResources().getStringArray(R.array.mcat_schedule_overview);
			
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return weeks.length;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return weeks[position];
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			viewholder = null;
			if (convertView == null) {
				viewholder = new Viewholder();
				convertView = inflater.inflate(R.layout.mcatschedule, null);
				viewholder.textview = (TextView)convertView.findViewById(R.id.mcat_textview);
				viewholder.textview.setText(weeks[position]);
				convertView.setTag(viewholder);
			}
			else {
				viewholder = (Viewholder)convertView.getTag();
				viewholder.textview.setText(weeks[position]);
			}
			return convertView;
		}
	}
	public class Viewholder {
		TextView textview;
		CheckBox checkbox;
	}
}
